import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/9/3
 * Time: 21:20
 */
public class Solution {
    public int[] missingTwo(int[] nums) {
        int temp = 0,length = nums.length;
        //把所有数异或在一起
        for (int cur : nums) {
            temp ^=  cur;
        }
        for (int i = 1; i <= length + 2; i++) {
            temp ^= i;
        }
        //2.找出比特位不同的那一位
        int x = 0;
        for (int i = 0; i < 32; i++) {
            if (((temp >> i) & 1) == 1){
                x = i;
                break;
            }
        }
        int a = 0,b = 0;
        //3.按照x位不同,分成两类异或
        for (int cur :  nums) {
            if (((cur >> x) & 1) == 1){
                a ^= cur;
            }else {
                b ^= cur;
            }
        }
        for (int i = 1; i <= length + 2; i++){
            if (((i >> x) & 1) == 1){
                a ^= i;
            }else {
                b ^= i;
            }
        }
        return new int[]{a, b};
    }
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] ret = solution.missingTwo(new int[]{1, 2, 3, 4});
        System.out.println(Arrays.toString(ret));
    }
}